package com.edu.exam.entity.assessment.technical;

import com.edu.exam.enums.assessment.technical.*;
import jakarta.persistence.*;
import lombok.Data;
import lombok.Builder;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import jakarta.persistence.Version;

import java.time.LocalDateTime;

/**
 * 跨模块质量对比实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：cross_module_comparison
 *
 * 根据E-06-03质量监控子模块设计实现
 * 对应cross_module_comparisons数据表，用于存储不同模块间的质量对比分析结果
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CrossModuleComparison {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "comparison_id", length = 32, unique = true, nullable = false)
    private String comparisonId;

    @Column(name = "comparison_name", length = 100, nullable = false)
    private String comparisonName;

    @Column(name = "comparison_type", length = 50, nullable = false)
    private String comparisonType;

    @Column(name = "time_range_start", nullable = false)
    private LocalDateTime timeRangeStart;

    @Column(name = "time_range_end", nullable = false)
    private LocalDateTime timeRangeEnd;

    @Column(name = "modules", columnDefinition = "JSON", nullable = false)
    private String modules;

    @Column(name = "comparison_criteria", columnDefinition = "JSON", nullable = false)
    private String comparisonCriteria;

    @Column(name = "comparison_result", columnDefinition = "JSON", nullable = false)
    private String comparisonResult;

    @Column(name = "key_findings", columnDefinition = "JSON")
    private String keyFindings;

    @Column(name = "recommendations", columnDefinition = "JSON")
    private String recommendations;

    @Column(name = "created_by", length = 32, nullable = false)
    private String createdBy;

    // 扩展字段
    @Column(name = "comparison_period", length = 50)
    private String comparisonPeriod; // 对比周期

    @Column(name = "baseline_module", length = 20)
    private String baselineModule; // 基准模块

    @Column(name = "comparison_scope", length = 50)
    private String comparisonScope; // 对比范围

    @Column(name = "data_sources", columnDefinition = "JSON")
    private String dataSources; // 数据来源

    @Column(name = "sample_sizes", columnDefinition = "JSON")
    private String sampleSizes; // 样本大小

    @Column(name = "statistical_significance", precision = 5, scale = 4)
    private Double statisticalSignificance; // 统计显著性

    @Column(name = "confidence_interval", columnDefinition = "JSON")
    private String confidenceInterval; // 置信区间

    @Column(name = "effect_size", precision = 5, scale = 4)
    private Double effectSize; // 效应大小

    @Column(name = "p_value", precision = 8, scale = 6)
    private Double pValue; // P值

    @Column(name = "hypothesis_test_result", columnDefinition = "JSON")
    private String hypothesisTestResult; // 假设检验结果

    @Column(name = "quality_metrics_comparison", columnDefinition = "JSON")
    private String qualityMetricsComparison; // 质量指标对比

    @Column(name = "performance_comparison", columnDefinition = "JSON")
    private String performanceComparison; // 性能对比

    @Column(name = "efficiency_comparison", columnDefinition = "JSON")
    private String efficiencyComparison; // 效率对比

    @Column(name = "consistency_comparison", columnDefinition = "JSON")
    private String consistencyComparison; // 一致性对比

    @Column(name = "fairness_comparison", columnDefinition = "JSON")
    private String fairnessComparison; // 公平性对比

    @Column(name = "trend_analysis", columnDefinition = "JSON")
    private String trendAnalysis; // 趋势分析

    @Column(name = "seasonal_adjustments", columnDefinition = "JSON")
    private String seasonalAdjustments; // 季节性调整

    @Column(name = "outlier_analysis", columnDefinition = "JSON")
    private String outlierAnalysis; // 异常值分析

    @Column(name = "correlation_analysis", columnDefinition = "JSON")
    private String correlationAnalysis; // 相关性分析

    @Column(name = "regression_analysis", columnDefinition = "JSON")
    private String regressionAnalysis; // 回归分析

    @Column(name = "variance_analysis", columnDefinition = "JSON")
    private String varianceAnalysis; // 方差分析

    @Column(name = "benchmark_comparison", columnDefinition = "JSON")
    private String benchmarkComparison; // 基准对比

    @Column(name = "industry_comparison", columnDefinition = "JSON")
    private String industryComparison; // 行业对比

    @Column(name = "historical_comparison", columnDefinition = "JSON")
    private String historicalComparison; // 历史对比

    @Column(name = "comparative_advantages", columnDefinition = "JSON")
    private String comparativeAdvantages; // 对比优势

    @Column(name = "comparative_disadvantages", columnDefinition = "JSON")
    private String comparativeDisadvantages; // 对比劣势

    @Column(name = "improvement_opportunities", columnDefinition = "JSON")
    private String improvementOpportunities; // 改进机会

    @Column(name = "best_practices_identified", columnDefinition = "JSON")
    private String bestPracticesIdentified; // 识别的最佳实践

    @Column(name = "lessons_learned", columnDefinition = "JSON")
    private String lessonsLearned; // 经验教训

    @Column(name = "action_items", columnDefinition = "JSON")
    private String actionItems; // 行动项目

    @Column(name = "implementation_plan", columnDefinition = "JSON")
    private String implementationPlan; // 实施计划

    @Column(name = "success_metrics", columnDefinition = "JSON")
    private String successMetrics; // 成功指标

    @Column(name = "monitoring_plan", columnDefinition = "JSON")
    private String monitoringPlan; // 监控计划

    @Column(name = "review_schedule", columnDefinition = "JSON")
    private String reviewSchedule; // 审查计划

    @Column(name = "report_format", length = 20)
    private String reportFormat; // 报告格式

    @Column(name = "report_template", length = 50)
    private String reportTemplate; // 报告模板

    @Column(name = "visualization_configs", columnDefinition = "JSON")
    private String visualizationConfigs; // 可视化配置

    @Column(name = "chart_definitions", columnDefinition = "JSON")
    private String chartDefinitions; // 图表定义

    @Column(name = "executive_summary", columnDefinition = "TEXT")
    private String executiveSummary; // 执行摘要

    @Column(name = "technical_appendix", columnDefinition = "TEXT")
    private String technicalAppendix; // 技术附录

    @Column(name = "data_quality_assessment", columnDefinition = "JSON")
    private String dataQualityAssessment; // 数据质量评估

    @Column(name = "limitations", columnDefinition = "JSON")
    private String limitations; // 局限性

    @Column(name = "assumptions", columnDefinition = "JSON")
    private String assumptions; // 假设条件

    @Column(name = "methodology", columnDefinition = "JSON")
    private String methodology; // 方法论

    @Column(name = "quality_assurance", columnDefinition = "JSON")
    private String qualityAssurance; // 质量保证

    @Column(name = "peer_review_status", length = 20)
    private String peerReviewStatus; // 同行评审状态

    @Column(name = "peer_reviewed_by", length = 32)
    private String peerReviewedBy; // 同行评审人

    @Column(name = "peer_review_date")
    private LocalDateTime peerReviewDate; // 同行评审日期

    @Column(name = "peer_review_comments", columnDefinition = "TEXT")
    private String peerReviewComments; // 同行评审意见

    @Column(name = "approval_status", length = 20)
    private String approvalStatus; // 审批状态

    @Column(name = "approved_by", length = 32)
    private String approvedBy; // 审批人

    @Column(name = "approval_date")
    private LocalDateTime approvalDate; // 审批日期

    @Column(name = "distribution_list", columnDefinition = "JSON")
    private String distributionList; // 分发列表

    @Column(name = "access_permissions", columnDefinition = "JSON")
    private String accessPermissions; // 访问权限

    @Column(name = "archived")
    private Boolean archived; // 是否已归档

    @Column(name = "archive_date")
    private LocalDateTime archiveDate; // 归档日期

    @Column(name = "retention_period_days")
    private Integer retentionPeriodDays; // 保留期限（天）

    @Column(name = "tags", length = 500)
    private String tags; // 标签（逗号分隔）

    @Column(name = "parent_comparison_id", length = 32)
    private String parentComparisonId; // 父对比ID

    @Column(name = "child_comparison_ids", columnDefinition = "JSON")
    private String childComparisonIds; // 子对比ID列表

    // ================================
    // 审计字段
    // ================================

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @Column(name = "version", nullable = false)
    private Integer version = 0;

    @Column(name = "is_deleted")
    private Boolean isDeleted = false;
}